<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="题目类型" prop="tmLx">
        <el-input
          v-model="queryParams.tmLx"
          placeholder="1:单选2:多选3:判断"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="题目章节" prop="tmZj">
        <el-input
          v-model="queryParams.tmZj"
          placeholder="请输入题目章节"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="题目内容" prop="tmNr">
        <el-input
          v-model="queryParams.tmNr"
          placeholder="请输入题目内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主题ID" prop="ztId">
        <el-input
          v-model="queryParams.ztId"
          placeholder="题目主题ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="题目状态" prop="tmZt">
        <el-input
          v-model="queryParams.tmZt"
          placeholder="0:未启用，1已启用"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否删除" prop="sfsc">
        <el-input
          v-model="queryParams.sfsc"
          placeholder="请输入是否删除"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否客观" prop="isMaterialQuestion">
        <el-input
          v-model="queryParams.isMaterialQuestion"
          placeholder="0否1是"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="正确答案(单选、判断)" prop="correctAnswer">
        <el-input
          v-model="queryParams.correctAnswer"
          placeholder="请输入正确答案(单选、判断)0:判断 1:单选2：多选3:简答"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:tmxx:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"

          @click="handleUpdate"
        >答题项</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:tmxx:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:tmxx:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:tmxx:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tmxxList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="题目ID"  width="95" align="center" prop="tmId" /> -->
      <el-table-column label="题目顺序" width="55" align="center" prop="tmSx" />
      <el-table-column label="题目内容" align="center" prop="tmNr" />
      <!-- <el-table-column label="题目描述describ" align="center" prop="tmMs" />  prop="tmLx" -->
      <el-table-column label="题目类型" width="55" align="center" >
        <template slot-scope="scope">
          {{scope.row.tmLx=='1'?'单选':scope.row.tmLx=='2'?'多选':'判断' }}
        </template>
      </el-table-column>

     <!-- <el-table-column label="题目章节" align="center" prop="tmZj" />
      <el-table-column label="题目主题ID" align="center" prop="ztId" />
      <el-table-column label="视频讲解url" align="center" prop="audioUrls" />
      <el-table-column label="试题库ID" align="center" prop="questionLibraryId" /> -->
      <el-table-column label="题目状态" width="55" align="center" prop="tmZt" />
      <!-- <el-table-column label="录入人" align="center" prop="lrr" />
      <el-table-column label="录入时间" align="center" prop="lrsj" />
      <el-table-column label="更新人" align="center" prop="gxr" />
      <el-table-column label="更新时间" align="center" prop="gxsj" />
      <el-table-column label="是否删除" align="center" prop="sfsc" /> -->
      <el-table-column label="是否客观题" width="65" align="center" >
        <template slot-scope="scope">
          {{scope.row.isMaterialQuestion=='0'?'否':'是' }}
        </template>
      </el-table-column>
      <!-- 题目选项 /ruankao/ztxx/list/dtx/    -->
      <el-table-column label="答题项" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <router-link :to="'/system/tmxx-dtx?tmId='+ scope.row.tmId+'&random='+Math.random()" class="link-type">
              答题项(<span>{{ scope.row.tmId }}</span>)
          </router-link>
        </template>
      </el-table-column>
     <!-- <el-table-column label="正确答案" width="55" align="center" prop="correctAnswer" /> -->
      <el-table-column label="操作" width="75" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:tmxx:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:tmxx:remove']"
          >删除</el-button>
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改试卷_题目信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="题目内容" prop="tmNr">
          <el-input v-model="form.tmNr" type="textarea"  placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="题目描述" prop="tmMs">
          <el-input v-model="form.tmMs" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="题目类型" prop="tmLx">
          <!-- <el-input v-model="form.tmLx" placeholder="请输入题目类型1:单选2：多选3:简答" /> -->
          <el-select v-model="form.tmLx" placeholder="请选择题目类型">
            <el-option label="单选" value="1"></el-option>
            <el-option label="多选" value="2"></el-option>
            <el-option label="判断" value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="题目顺序" prop="tmSx">
          <el-input v-model="form.tmSx" placeholder="请输入题目顺序" />
        </el-form-item>
        <el-form-item label="题目章节" prop="tmZj">
          <!-- <el-input v-model="form.tmZj" placeholder="请输入题目章节" /> @change="hdlxYjClick" -->
          <el-select v-model="form.tmZj" style="width: 49%" placeholder="请选择题目章节" >
    				<el-option
    					v-for="item in zjxxList"
    						:key="item.zjId"
    						:label="item.zjId+'-'+item.zjMc"
    						:value="item.zjId">
    				</el-option>
  				</el-select>
        </el-form-item>
        <el-form-item label="题目主题ID" prop="ztId">
          <!-- 	大数据专业系统研发职称考试 -->
          <!-- <el-input v-model="form.ztId" placeholder="请输入题目主题ID" /> -->
          <el-radio-group v-model="form.ztId">
             <el-radio label="1">大数据专业系统研发</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="视频讲解url" prop="audioUrls">
          <el-input v-model="form.audioUrls" placeholder="请输入视频讲解url" />
        </el-form-item>
        <!-- <el-form-item label="试题库ID" prop="questionLibraryId">
          <el-input v-model="form.questionLibraryId" placeholder="请输入试题库ID" />
        </el-form-item> -->
        <el-form-item label="启用状态" prop="tmZt">
          <!-- <el-input v-model="form.tmZt" placeholder="请输入0:未启用，1已启用" /> -->
          <el-select v-model="form.tmLx" placeholder="是否启用">
            <el-option label="启用" value="1"></el-option>
            <el-option label="停用" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="录入人" prop="lrr">
          <el-input v-model="form.lrr" placeholder="请输入录入人" />
        </el-form-item>
        <el-form-item label="录入时间" prop="lrsj">
          <!-- <el-input v-model="form.lrsj" placeholder="请输入录入时间" /> -->
          <el-date-picker
                v-model="form.lrsj"
                type="datetime"
                placeholder="选择日期时间">
           </el-date-picker>
        </el-form-item>
        <el-form-item label="更新人" prop="gxr">
          <el-input v-model="form.gxr" placeholder="请输入更新人" />
        </el-form-item>
        <el-form-item label="更新时间" prop="gxsj">
          <!-- <el-input v-model="form.gxsj" placeholder="请输入更新时间" /> -->
          <el-date-picker
                v-model="form.gxsj"
                type="datetime"
                placeholder="选择日期时间">
           </el-date-picker>
        </el-form-item>
        <el-form-item label="是否删除" prop="sfsc">
          <!-- <el-input v-model="form.sfsc" placeholder="请输入是否删除" /> -->
          <el-radio-group v-model="form.sfsc">
             <el-radio label="0">否</el-radio>
             <el-radio label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否客观题" prop="isMaterialQuestion">
          <!-- <el-input v-model="form.isMaterialQuestion" placeholder="请输入是否客观题" /> -->
          <el-radio-group v-model="form.isMaterialQuestion">
             <el-radio label="0">否</el-radio>
             <el-radio label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="正确答案" prop="correctAnswer">
          <el-input v-model="form.correctAnswer" placeholder="请输入正确答案" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTmxx, getTmxx, delTmxx, addTmxx, updateTmxx } from "@/api/system/tmxx";
import { listTmzj } from "@/api/system/tmzj";
export default {
  name: "Tmxx",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 试卷_题目信息表格数据
      tmxxList: [],
      // 章节信息
      zjxxList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tmNr: null,
        tmMs: null,
        tmLx: 1,
        tmSx: null,
        tmZj: null,
        ztId: '1',
        audioUrls: null,
        questionLibraryId: '1',
        tmZt: null,
        lrr: null,
        lrsj: null,
        gxr: null,
        gxsj: null,
        sfsc: null,
        isMaterialQuestion: null,
        correctAnswer: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getZjList();
  },
  methods: {
    /** 查询试卷_题目信息列表 */
    getList() {
      this.loading = true;
      listTmxx(this.queryParams).then(response => {
        this.tmxxList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询试卷_试卷主题信息列表 */
    getZjList() {
      this.loading = true;
      listTmzj(this.queryParams).then(response => {
        this.zjxxList = response.rows;
       /* this.total = response.total;
        this.loading = false; */
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        tmId: null,
        tmNr: null,
        tmMs: null,
        tmLx: null,
        tmSx: null,
        tmZj: null,
        ztId: null,
        audioUrls: null,
        questionLibraryId: null,
        tmZt: null,
        lrr: null,
        lrsj: null,
        gxr: null,
        gxsj: null,
        sfsc: null,
        isMaterialQuestion: null,
        correctAnswer: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.tmId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加试卷_题目信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const tmId = row.tmId || this.ids
      getTmxx(tmId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改试卷_题目信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.tmId != null) {
            updateTmxx(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTmxx(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const tmIds = row.tmId || this.ids;
      this.$modal.confirm('是否确认删除试卷_题目信息编号为"' + tmIds + '"的数据项？').then(function() {
        return delTmxx(tmIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/tmxx/export', {
        ...this.queryParams
      }, `tmxx_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
